#include<iostream>
#include<cmath>
#include<limits>
#include"EquationSolver.h"

 class myf_1 : public Function
  {
  public:
    double operator()(double x) {
      return 1/x-tan(x);
    }
  };
  class myf_2 : public Function
  {
  public:
    double operator()(double x){
      return 1/x-pow(2,x);
    }
  };
  class myf_3 : public Function
  {
  public:
    double operator()(double x){
      return pow(2,-x)+exp(x)+2*cos(x)-6;
    }
  };
  class myf_4 : public Function
  {
  public:   
    double operator()(double x){
      return (x*x*x+4*x*x+3*x+5)/(2*x*x*x-9*x*x+18*x-2);
    }
  };

int main(void){
  myf_1 f_1;
  myf_2 f_2;
  myf_3 f_3;
  myf_4 f_4;
  Bisection<myf_1> bis_1(0, acos(-1)/2, 100, epsilon, f_1);
  Bisection<myf_2> bis_2(0, 1, 100, epsilon, f_2);
  Bisection<myf_3> bis_3(1, 3, 100, epsilon, f_3);
  Bisection<myf_4> bis_4(0, 4, 100, epsilon, f_4);
  double *R_1 = bis_1.solve();
  double *R_2 = bis_2.solve();
  double *R_3 = bis_3.solve();
  double *R_4 = bis_4.solve();
  std::cout<<"第一的根为"<<R_1[0]<<",迭代次数为"<<R_1[1]<<",误差为"<<f_1(R_1[0])<<std::endl;
  std::cout<<"**************************************************************"<<std::endl;
  std::cout<<"第二的根为"<<R_2[0]<<",迭代次数为"<<R_2[1]<<",误差为"<<f_2(R_2[0])<<std::endl;
  std::cout<<"**************************************************************"<<std::endl;
  std::cout<<"第三的根为"<<R_3[0]<<",迭代次数为"<<R_3[1]<<",误差为"<<f_3(R_3[0])<<std::endl;
  std::cout<<"**************************************************************"<<std::endl;
  std::cout<<"第四的根为"<<R_4[0]<<",迭代次数为"<<R_4[1]<<",误差为"<<f_4(R_4[0])<<std::endl;
  return 0;
}





